package com.xxx.yuedong.mall.controller;

import com.github.pagehelper.PageInfo;
import com.xxx.yuedong.common.R;
import com.xxx.yuedong.mall.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 描述：     订单后台管理Controller
 * @author hc
 */
@RestController
@Api(tags = "后台订单管理相关接口")
@Slf4j
public class OrderAdminController {

    @Autowired
    OrderService orderService;

    @GetMapping("admin/order/list")
    @ApiOperation(value = "管理员订单列表")
    public R listForAdmin(@RequestParam Integer pageNum,
                          @RequestParam Integer pageSize) {
        PageInfo pageInfo = orderService.listForAdmin(pageNum, pageSize);
        return R.ok().put("page",pageInfo);
    }

    /**
     * 发货。订单状态流程：0用户已取消，10未付款，20已付款，30已发货，40交易完成
     */
    @PostMapping("admin/order/delivered")
    @ApiOperation(value = "管理员发货")
    public R delivered(@RequestParam String orderNo) {
        orderService.deliver(orderNo);
        return R.ok();
    }

    /**
     * 完结订单。订单状态流程：0用户已取消，10未付款，20已付款，30已发货，40交易完成。管理员和用户都可以调用
     */
    @PostMapping("order/finish")
    @ApiOperation(value = "完结订单")
    public R finish(@RequestParam String orderNo) {
        orderService.finish(orderNo);
        return R.ok();
    }

    @ApiOperation(value = "后台查询收件人信息接口")
    @GetMapping("/admin/product/receiver")
    public R receiver(@RequestParam Long orderNo) {
        HashMap map = orderService.searchReceiver(orderNo);
        return R.ok().put("param",map);
    }
}
